class LoginController < ApplicationController
  layout "main"
  
  def authorize
    # just overriding stabndard ApplicationController authorize method
  end
  
  def index
    session[:user_id]=nil
  end
  
  def login
    session[:user_id]=nil
    if params[:user]
      logged_in=User.find(:first, 
        :conditions => ["login = ? AND password = ? ", params[:user][:login], params[:user][:password] ])
      unless logged_in.nil?
        session[:user_id]=logged_in.id
      else
        flash[:notice] = "Wrong username or password."
      end
    end
    
    if (session[:user_id].nil?)
#      render :text => "not logged" and return true
      redirect_to :action => "index" and return true
    else
#      render :text => "logged "  + session[:user_id].to_s and return true
      redirect_to :controller => "bugs", :action => "index" and return true
    end
  end
end
